/**
 * 
 */
package wangjg.game.widget;

import java.util.ArrayList;
import java.util.List;

import wangjg.game.layer.Graphics;
import wangjg.game.layout.Box;
import wangjg.game.layout.LayoutUtil;
import wangjg.game.layout.PercentProperty;

/**
 * @author wangjg
 *
 */
public class Container extends Widget {
	private List<Box> children = new ArrayList<Box>();
	
	public Container(int absWidth, int absHeight, int spacing) {
		this.pp.setAbsWidth(absWidth);
		this.pp.setAbsHeight(absHeight);
		this.pp.setAbsSpacing(spacing);
	}
	
	public Container(float widthPercent, float heightPercent, int spacing) {
		pp.setWidthPercent(widthPercent);
		pp.setHeightPercent(heightPercent);
		pp.setAbsSpacing(spacing);
	}
	public void addChild(Box child){
		children.add(child);
	}
	
	public void paint(Graphics g) {
		if(pp.getVisible()!=PercentProperty.DISPLAY_VISIBLE){
			return;
		}
		LayoutUtil.computeChildren(this);
		int[] ca = new int[]{0xFF990000, 0xFF009900, 0xFF000099, 0xFF990099};
		int c = ca[id%3];
		g.setColor(c);
//		g.drawRect(pp.getAbsX(), pp.getAbsY(), pp.getAbsWidth(), pp.getAbsHeight());
		for(Box box:children){
			PercentProperty bpp = box.getPercentProperty();
			if(bpp.getVisible()!=PercentProperty.DISPLAY_VISIBLE){
				continue;
			}
			if(box instanceof Container){
				((Container)box).paint(g);
			}else{
				((Widget)box).paint(g);
			}
		}
	}

	public List<Box> getChildren() {
		return children;
	}

	public PercentProperty getPercentProperty() {
		return pp;
	}

}